package setup

import (
	"context"
	"github.com/lishimeng/go-log"
	"time"
)

func Init(ctx context.Context) (err error) {
	log.Debug("setup delayed components delay 3s")

	go func() {
		select {
		case <-ctx.Done():
			return
		case <-time.After(time.Second*3):
			delayedComps := []func(context.Context)error{clearFleJob}
			err = _init(ctx, delayedComps...)
		}
	}()
	return
}

func _init(ctx context.Context, comps ...func(context.Context)error) (err error) {
	for _, item := range comps {
		err = item(ctx)
		if err != nil {
			return
		}
	}
	return
}
